import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class About extends StatefulWidget {
  About({Key key, @required this.type, @required this.name}) : super(key: key);
  String type = '';
  String name = '';

  @override
  _AboutState createState() => _AboutState();
}

Widget body(String content, int index) {
  return Row(
    children: [
      Expanded(
        child: Text(
          index == 0 ? content : "${index}、${content}",
          style: TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.w400,
          ),
        ),
      ),
    ],
  );
}

List<Widget> initBodyList(arr) {
  List<Widget> bodyList = [
    SizedBox(height: 10),
    Row(
      children: [
        Padding(
            padding: EdgeInsets.only(top: 10),
            child: Text(
              "回收方法：",
              maxLines: 5,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                fontSize: 22,
                fontWeight: FontWeight.w700,
              ),
            ))
      ],
    ),
    SizedBox(height: 10),
  ];
  List.generate(arr.length, (index) {
    bodyList.add(Padding(
      padding: EdgeInsets.only(left: 15, top: 5, right: 15, bottom: 5),
      child: body(arr[index], index + 1),
    ));
  });
  return bodyList;
}

class _AboutState extends State<About> {
  Map obj = {
    'chu': {
      'sub': '即易腐垃圾，是指食材废料、剩菜剩饭、过期食品、瓜果皮核、花卉绿植、中药药渣等生物质，生活废弃物',
      'bodyList': [
        '流质食物垃圾，如牛奶等，应直接倒入下水道',
        '有包装物的湿垃圾应将包装物去除后分类投放',
        '包装物请投放到对应的可回收物或干垃圾容器'
      ]
    },
    'other': {
      'sub': '即其他垃圾，是指除可回收物、有害垃圾、湿垃圾意外的其他生活垃圾',
      'bodyList': ['尽量沥干水分', '有包装物的湿垃圾应将包装物去除后分类投放', '难以辨别类别的生活垃圾投入到干垃圾容器内']
    },
    'hai': {
      'sub': '废电池、废灯管、废药品、废油漆及其容器对人体健康或者自然环境造成直接或者潜在危害的生活废弃物。',
      'bodyList': ['投放时请注意轻放', '已破损的请连带包装或包裹后投放', '如易挥发，请密封后投放']
    },
    'hui': {
      'sub': '废纸张、废塑料、废玻璃制品、废金属、废织物等适宜回收，可循环利用的生活废弃物。',
      'bodyList': [
        '轻投轻放，清洁干燥，避免污染',
        '废纸尽量平整',
        '立体包装物请清空内容物，清洁后压扁投放',
        '有尖锐边角的，应包裹后投放'
      ]
    }
  };
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(
            "${widget.name}简介",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              fontSize: 15,
            ),
          ),
        ),
        body: SingleChildScrollView(
            child: Container(
          width: MediaQuery.of(context).size.width,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Image.asset('assets/images/${widget.type}_type.png'),
              SizedBox(height: 15),
              Text(
                widget.name == 'chu'
                    ? "${widget.name}等湿垃圾"
                    : widget.name == 'other'
                        ? "${widget.name}等干垃圾"
                        : widget.name,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 20,
                  fontWeight: FontWeight.w500,
                ),
              ),
              Padding(
                padding: EdgeInsets.only(left: 15, top: 10, right: 15),
                child: body(obj[widget.type]['sub'], 0),
              ),
              ...initBodyList(obj[widget.type]['bodyList'])
            ],
          ),
        )));
  }
}
